home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / src-server / wc_MessageB.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-04  |  11.3 KB  |  275 lines

  1. /* -*-C-*-
  2. ********************************************************************************
  3. *
  4. * File:         wc_MessageB.c
  5. * RCS:          $Header: wc_MessageB.c,v 1.3 91/03/14 03:14:53 mayer Exp $
  6. * Description:  XM_MESSAGE_BOX_WIDGET_CLASS
  7. * Author:       Niels Mayer, HPLabs
  8. * Created:      Sat Oct 28 03:40:20 1989
  9. * Modified:     Thu Oct  3 23:55:57 1991 (Niels Mayer) mayer@hplnpm
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       X11r5 contrib tape release
  13. *
  14. * WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. * XLISP version 2.1, Copyright (c) 1989, by David Betz.
  16. *
  17. * Permission to use, copy, modify, distribute, and sell this software and its
  18. * documentation for any purpose is hereby granted without fee, provided that
  19. * the above copyright notice appear in all copies and that both that
  20. * copyright notice and this permission notice appear in supporting
  21. * documentation, and that the name of Hewlett-Packard and David Betz not be
  22. * used in advertising or publicity pertaining to distribution of the software
  23. * without specific, written prior permission.  Hewlett-Packard and David Betz
  24. * make no representations about the suitability of this software for any
  25. * purpose. It is provided "as is" without express or implied warranty.
  26. *
  27. * HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  28. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  29. * IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  30. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  31. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  32. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  33. * PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * See ./winterp/COPYRIGHT for information on contacting the authors.
  36. * Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  37. * Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  38. *
  39. ********************************************************************************
  40. */
  41. static char rcs_identity[] = "@(#)$Header: wc_MessageB.c,v 1.3 91/03/14 03:14:53 mayer Exp $";
  42.  
  43. #include <stdio.h>
  44. #include <Xm/Xm.h>
  45. #include <Xm/MessageB.h>
  46. #include "winterp.h"
  47. #include "user_prefs.h"
  48. #include "xlisp/xlisp.h"
  49. #include "w_funtab.h"
  50.  
  51. static LVAL k_message_dialog;
  52. static LVAL k_error_dialog;
  53. static LVAL k_information_dialog;
  54. static LVAL k_question_dialog;
  55. static LVAL k_warning_dialog;
  56. static LVAL k_working_dialog;
  57.  
  58.  
  59. extern Widget Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(); /* w_classes.c */
  60.  
  61.  
  62. /*****************************************************************************
  63.  * (send XM_MESSAGE_BOX_WIDGET_CLASS :new 
  64.  *                           [:managed/:unmanaged]
  65.  *                           [:message_dialog/:error_dialog/
  66.  *                            :information_dialog,:question_dialog,
  67.  *                            :warning_dialog,:working_dialog]
  68.  *                           [<name>]
  69.  *                           <parent> 
  70.  *                           [:XMN_<arg1> <val1>]
  71.  *                           [. . .             ]
  72.  *                           [:XMN_<argN> <valN>])
  73.  *
  74.  * The optional keyword submessage :managed will cause a subsequent call
  75.  * to XtManageChild(). If the submessage :unmanaged is present, or no
  76.  * submessage, then XtManageChild() won't be called, and the resulting
  77.  * widget will be returned unmanaged.
  78.  *
  79.  *    (send XM_MESSAGE_BOX_WIDGET_CLASS :new ...)
  80.  *    --> XmCreateMessageBox();
  81.  *    (send XM_MESSAGE_BOX_WIDGET_CLASS :new :message_dialog ...)
  82.  *    --> XmCreateMessageDialog();
  83.  *    (send XM_MESSAGE_BOX_WIDGET_CLASS :new :error_dialog ...)
  84.  *    --> XmCreateErrorDialog();
  85.  *     (send XM_MESSAGE_BOX_WIDGET_CLASS :new :information_dialog ...)
  86.  *     --> XmCreateInformationDialog();
  87.  *     (send XM_MESSAGE_BOX_WIDGET_CLASS :new :question_dialog ...)
  88.  *     --> XmCreateQuestionDialog();
  89.  *     (send XM_MESSAGE_BOX_WIDGET_CLASS :new :warning_dialog ...)
  90.  *     --> XmCreateWarningDialog();
  91.  *     (send XM_MESSAGE_BOX_WIDGET_CLASS :new :working_dialog ...)
  92.  *     --> XmCreateWorkingDialog();
  93.  ****************************************************************************/
  94. LVAL Xm_Message_Box_Widget_Class_Method_ISNEW()
  95. {
  96.   extern ArgList Wres_Get_LispArglist(); /* from w_resources.c */
  97.   extern void    Wres_Free_C_Arglist_Data(); /* from w_resources.c */
  98.   extern LVAL k_managed, k_unmanaged;
  99.   LVAL self, o_parent;
  100.   char* name;
  101.   Boolean managed_p;
  102.   LVAL dialog_kind;
  103.   Widget widget_id, parent_widget_id;
  104.  
  105.   self = xlgaobject();        /* NOTE: xlobj.c:clnew() returns an OBJECT; if this method
  106.                    returns successfully, it will return a WIDGETOBJ */
  107.   
  108.   /* get optional managed/unmanaged arg */
  109.   if (moreargs() && ((*xlargv == k_managed) || (*xlargv == k_unmanaged)))
  110.     managed_p = (nextarg() == k_managed);
  111.   else
  112.     managed_p = FALSE;        /* by default don't call XtManageChild() */
  113.  
  114.   /* get optional :message_dialog/:error_dialog/... arg */
  115.   if (moreargs() && ((*xlargv == k_message_dialog)     ||
  116.              (*xlargv == k_error_dialog)       ||
  117.              (*xlargv == k_information_dialog) ||
  118.              (*xlargv == k_question_dialog)    ||
  119.              (*xlargv == k_warning_dialog)     ||
  120.              (*xlargv == k_working_dialog)))
  121.     dialog_kind = nextarg();
  122.   else
  123.     dialog_kind = NIL;        /* default is XmCreateMessageBox() */
  124.  
  125.   /* get optional <name> arg */
  126.   if (moreargs() && (stringp(*xlargv)))
  127.     name = (char*) getstring(nextarg());
  128.   else
  129.     name = "";            /* default name */
  130.  
  131.   /* get required <parent> widget-object arg */
  132.   parent_widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&o_parent);
  133.  
  134.   /*
  135.    * Store the widget object <self> in the XmNuserData resource on the
  136.    * widget. This will allow us to retrieve the widget object from Xtoolkit
  137.    * functions returning widget ID's without having to keep around a table
  138.    * of widgetID-->widget-objects.
  139.    */
  140.    ARGLIST_RESET(); ARGLIST_ADD(XmNuserData, (XtArgVal) self); 
  141.  
  142.   if (moreargs()) {        /* if there are more arguments, */
  143.     Cardinal xt_numargs;    /* then we have some extra widget resources to set */
  144.     ArgList xt_arglist = Wres_Get_LispArglist(self, parent_widget_id, ARGLIST(), &xt_numargs);
  145.     if (dialog_kind == NIL)
  146.       widget_id = XmCreateMessageBox(parent_widget_id, name, xt_arglist, xt_numargs);
  147.     else if (dialog_kind == k_message_dialog)
  148.       widget_id = XmCreateMessageDialog(parent_widget_id, name, xt_arglist, xt_numargs);
  149.     else if (dialog_kind == k_error_dialog)
  150.       widget_id = XmCreateErrorDialog(parent_widget_id, name, xt_arglist, xt_numargs);
  151.     else if (dialog_kind == k_information_dialog)
  152.       widget_id = XmCreateInformationDialog(parent_widget_id, name, xt_arglist, xt_numargs);
  153.     else if (dialog_kind == k_question_dialog)
  154.       widget_id = XmCreateQuestionDialog(parent_widget_id, name, xt_arglist, xt_numargs);
  155.     else if (dialog_kind == k_warning_dialog)
  156.       widget_id = XmCreateWarningDialog(parent_widget_id, name,    xt_arglist, xt_numargs);
  157.     else if (dialog_kind == k_working_dialog)
  158.       widget_id = XmCreateWorkingDialog(parent_widget_id, name, xt_arglist, xt_numargs);
  159.     else
  160.       xlfatal("Bug in Xm_Message_Box_Widget_Class_Method_ISNEW()");
  161.     Wres_Free_C_Arglist_Data();
  162.   }
  163.   else 
  164.     if (dialog_kind == NIL)
  165.       widget_id = XmCreateMessageBox(parent_widget_id, name, ARGLIST());
  166.     else if (dialog_kind == k_message_dialog)
  167.       widget_id = XmCreateMessageDialog(parent_widget_id, name, ARGLIST());
  168.     else if (dialog_kind == k_error_dialog)
  169.       widget_id = XmCreateErrorDialog(parent_widget_id, name, ARGLIST());
  170.     else if (dialog_kind == k_information_dialog)
  171.       widget_id = XmCreateInformationDialog(parent_widget_id, name, ARGLIST());
  172.     else if (dialog_kind == k_question_dialog)
  173.       widget_id = XmCreateQuestionDialog(parent_widget_id, name, ARGLIST());
  174.     else if (dialog_kind == k_warning_dialog)
  175.       widget_id = XmCreateWarningDialog(parent_widget_id, name, ARGLIST());       
  176.     else if (dialog_kind == k_working_dialog)
  177.       widget_id = XmCreateWorkingDialog(parent_widget_id, name, ARGLIST());
  178.     else
  179.       xlfatal("Bug in Xm_Message_Box_Widget_Class_Method_ISNEW()");
  180.  
  181.   Wcls_Initialize_WIDGETOBJ(self, widget_id);
  182.  
  183.   if (managed_p)
  184.     XtManageChild(widget_id);
  185.   
  186. #ifdef DEBUG_WINTERP_1
  187.   Wcls_Print_WidgetObj_Info(self);
  188. #endif
  189.   return (self);
  190. }
  191.  
  192.  
  193. /*****************************************************************************
  194.  * (send <messageboxwidget> :GET_CHILD <symbol>)
  195.  * This method returns  a WIDGETOBJ, the child of <messageboxwidget> 
  196.  * corresponding to <symbol>:
  197.  * :DIALOG_DEFAULT_BUTTON
  198.  * :DIALOG_SYMBOL_LABEL
  199.  * :DIALOG_MESSAGE_LABEL
  200.  * :DIALOG_OK_BUTTON
  201.  * :DIALOG_CANCEL_BUTTON
  202.  * :DIALOG_HELP_BUTTON
  203.  * :DIALOG_SEPARATOR
  204.  *
  205.  * Widget XmMessageBoxGetChild (widget, child)
  206.  * Widget          widget;
  207.  * unsigned char   child;
  208.  ****************************************************************************/
  209. LVAL Xm_Message_Box_Widget_Class_Method_GET_CHILD()
  210. {
  211.   extern LVAL Wcls_WidgetID_To_WIDGETOBJ();
  212.   extern LVAL s_XmDIALOG_DEFAULT_BUTTON, s_XmDIALOG_SYMBOL_LABEL,
  213.   s_XmDIALOG_MESSAGE_LABEL, s_XmDIALOG_OK_BUTTON, s_XmDIALOG_CANCEL_BUTTON,
  214.   s_XmDIALOG_HELP_BUTTON, s_XmDIALOG_SEPARATOR;
  215.   LVAL self, lval_child;
  216.   Widget widget_id;
  217.   unsigned char child;
  218.   
  219.   widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&self);
  220.   lval_child = xlgasymbol();
  221.   xllastarg();
  222.   
  223.   if (lval_child == s_XmDIALOG_DEFAULT_BUTTON)
  224.     child = XmDIALOG_DEFAULT_BUTTON;
  225.   else if (lval_child == s_XmDIALOG_SYMBOL_LABEL)
  226.     child = XmDIALOG_SYMBOL_LABEL;
  227.   else if (lval_child == s_XmDIALOG_MESSAGE_LABEL)
  228.     child = XmDIALOG_MESSAGE_LABEL;
  229.   else if (lval_child == s_XmDIALOG_OK_BUTTON)
  230.     child = XmDIALOG_OK_BUTTON;
  231.   else if (lval_child == s_XmDIALOG_CANCEL_BUTTON)
  232.     child = XmDIALOG_CANCEL_BUTTON;
  233.   else if (lval_child == s_XmDIALOG_HELP_BUTTON)
  234.     child = XmDIALOG_HELP_BUTTON;
  235.   else if (lval_child == s_XmDIALOG_SEPARATOR)
  236.     child = XmDIALOG_SEPARATOR;
  237.   else 
  238.     xlerror("MESSAGE_BOX_WIDGET_CLASS method :GET_CHILD -- unknown child type.", lval_child);
  239.  
  240.   return (Wcls_WidgetID_To_WIDGETOBJ(XmMessageBoxGetChild(widget_id, child)));  
  241. }
  242.  
  243. /******************************************************************************
  244.  *
  245.  ******************************************************************************/
  246. Wc_MessageB_Init()
  247. {
  248.   LVAL o_XM_MESSAGE_BOX_WIDGET_CLASS;
  249.   extern LVAL Wcls_Create_Subclass_Of_WIDGET_CLASS(); /* w_classes.c */
  250.   extern      xladdmsg();    /* from xlobj.c */
  251.  
  252.   k_message_dialog     = xlenter(":MESSAGE_DIALOG");
  253.   k_error_dialog       = xlenter(":ERROR_DIALOG");
  254.   k_information_dialog = xlenter(":INFORMATION_DIALOG");
  255.   k_question_dialog    = xlenter(":QUESTION_DIALOG");
  256.   k_warning_dialog     = xlenter(":WARNING_DIALOG");
  257.   k_working_dialog     = xlenter(":WORKING_DIALOG");
  258.  
  259.   o_XM_MESSAGE_BOX_WIDGET_CLASS =
  260.     Wcls_Create_Subclass_Of_WIDGET_CLASS("XM_MESSAGE_BOX_WIDGET_CLASS",
  261.                      xmMessageBoxWidgetClass);
  262.   
  263.   /* a special :isnew method on this class allows for the creation of this
  264.      widget inside a popup shell if one of the following submessage keywords
  265.      are given: 
  266.      :message_dialog, :error_dialog, :information_dialog, 
  267.      :question_dialog, :warning_dialog, :working_dialog */
  268.   xladdmsg(o_XM_MESSAGE_BOX_WIDGET_CLASS, ":ISNEW", 
  269.        FTAB_Xm_Message_Box_Widget_Class_Method_ISNEW);
  270.  
  271.   xladdmsg(o_XM_MESSAGE_BOX_WIDGET_CLASS, ":GET_CHILD", 
  272.        FTAB_Xm_Message_Box_Widget_Class_Method_GET_CHILD);
  273. }
  274.